#ifndef MYMUSIC_WLVIDEO_H
#define MYMUSIC_WLVIDEO_H

#include "../bean/WlQueue.h"
#include "../bean/WlCallJava.h"
#include "../audio/WlAudio.h"



extern "C"
{
#include "../thirdpart/libswscale/swscale.h"
#include "../thirdpart/libavutil/imgutils.h"
#include "../thirdpart/libavutil/time.h"
#include "../thirdpart/libavcodec/avcodec.h"
};

class WlVideo {

public:
    int streamIndex = -1;
    double clock = 0;
    double delayTime = 0;
    double defaultDelayTime = 0.04;

    AVCodecContext *avCodecContext = NULL;
    AVCodecParameters *codecpar = NULL;
    AVBSFContext *abs_ctx = NULL;
    AVRational time_base;

    WlQueue *queue = NULL;
    WlPlaystatus *playstatus = NULL;
    WlCallJava *wlCallJava = NULL;
    WlAudio *audio = NULL;

    pthread_t thread_play;
    pthread_mutex_t codecMutex;


public:
    WlVideo(WlPlaystatus *playstatus, WlCallJava *wlCallJava);
    ~WlVideo();
    void play();
    void release();
    /**计算 视屏帧 和音频 的pts 相差值*/
    double getFrameDiffTime(AVFrame *avFrame, AVPacket *avPacket);
    /** 计算延迟播放时间，音频同步*/
    double getDelayTime(double diff);

};


#endif //MYMUSIC_WLVIDEO_H
